﻿Imports System
Imports System.CodeDom
Imports System.ComponentModel
Imports System.Globalization
Imports System.Workflow.Activities.Rules

Namespace System.Workflow.Activities.Rules.Design
    Friend Class RuleConditionReferenceExpressionTypeConverter
        Inherits TypeConverter
        ' Methods
        Friend Sub New()
        End Sub

        Public Overrides Function CanConvertTo(ByVal context As ITypeDescriptorContext, ByVal destinationType As Type) As Boolean
            Return ((destinationType Is GetType(String)) OrElse MyBase.CanConvertTo(context, destinationType))
        End Function

        Public Overrides Function ConvertTo(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object, ByVal destinationType As Type) As Object
            If (context Is Nothing) Then
                Throw New ArgumentNullException("context")
            End If
            If (Not destinationType Is GetType(String)) Then
                Return MyBase.ConvertTo(context, culture, value, destinationType)
            End If
            Dim expression As CodeExpression = [TryCast](value,CodeExpression)
            If (expression Is Nothing) Then
                Return Messages.ConditionExpression
            End If
            Return New RuleExpressionCondition(expression).ToString
        End Function

    End Class
End Namespace

